package com.cloudRestudy.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName : RouterConfig
 * @Author : lby
 * @Date: 2021/7/31 16:06
 * @Description : gateway路由转发配置
 * 这里的配置可以卸载数据库中或者是配置文件
 */
@Configuration
public class RouterConfig {
    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("CLOUD-PAYMENT",
                        r -> r.path("/payment/**").filters(f -> f.stripPrefix(1)).uri("http://127.0.0.1:8001"))
                .route("CLOUD-CUSTOMER",
                        r -> r.path("/customer/**").filters(f -> f.stripPrefix(1)).uri("http://127.0.0.1:80"))
                .route("CLOUD-GATEWAY",
                        r -> r.path("/gateway/**").filters(f -> f.stripPrefix(1)).uri("http://127.0.0.1:9999"))
                .build();
    }
}
